package com.api.shopapi.mapper;


import com.api.shopapi.entity.Device;
import com.api.shopapi.entity.dto.DeviceDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface DeviceMapper {


    @Insert("insert into  device " +
            "(" +
            "DeviceCode, " +
            "Name, " +
            "Imei, " +
            "Status, " +
            "CreateTime, " +
            "StaffCode, " +
            "GovernmentCode," +
            "BusinessCode," +
            "ServeCode" +
            ") " +
            "VALUES " +
            "(" +
            "#{device.DeviceCode} ," +
            "#{device.Name} ," +
            "#{device.Imei} ," +
            "#{device.Status} ," +
            "#{device.CreateTime} ," +
            "#{device.StaffCode} ," +
            "#{device.GovernmentCode}, " +
            "#{device.BusinessCode}, " +
            "#{device.ServeCode} " +
            ")")
    int insert(@Param("device") Device device);


    @Update("update  device " +
            "set " +
            "Name=#{device.Name} ," +
            "Imei=#{device.Imei} ," +
            "Status=#{device.Status} ," +
            "StaffCode=#{device.StaffCode}," +
            "GovernmentCode=#{device.GovernmentCode}, " +
            "BusinessCode=#{device.BusinessCode}, " +
            "ServeCode=#{device.ServeCode} " +
            "where " +
            "DeviceCode=#{device.DeviceCode}  ")
    int update(@Param("device") Device device);


    @Select("select  *  from device " +
            "where " +
            "DeviceCode=#{deviceCode} ")
    Device getByDeviceCode(@Param("deviceCode") String deviceCode);


    @Select("<script>" +
            " select  * from  device as d " +
            " where " +
            " d.GovernmentCode=#{governmentCode}" +
            " <if test ='businessCode !=\"00000000-0000-0000-0000-000000000000\" '> " +
            " and d.BusinessCode =#{businessCode}  " +
            " </if>" +
            " </script> ")
    List<DeviceDTO> getPageList(@Param("governmentCode")String governmentCode,
                                @Param("businessCode") String businessCode);

    @Select("select * from  device where ServeCode=#{serveCode} ")
    Device getByServeCode(@Param("serveCode") String serveCode);


    @Select("select  * from  device where Imei=#{imei} ")
    Device getByImei(@Param("imei") String imei);


    @Select("select  * from device where businessCode=#{businessCode} ")
    List<Device> getListByBusinessCode(String businessCode);
}
